import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:wanxiang_app/pages/index.dart';

import '../utils/constant.dart';
import 'package:get/get.dart';

import '../utils/tabChangeEvent.dart';
class ChatAppBar extends AppBar {
  final GlobalKey<NavigatorState> navigatorKey =
  new GlobalKey<NavigatorState>();

  ChatAppBar(
      {required BuildContext context,
        title,
        online,
        hasLeading = false,
        popWithParam,
        showSearch = false,
        showFilter = false,
        callBack = Function})
      : super(
      bottom: PreferredSize(
          child: Container(
            color: Color(0xFFDDDDDD),
            width: double.infinity,
            height: 0.5,
          ),
          preferredSize: Size.fromHeight(0)),
      title: Container(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(
              title,
              style: TextStyle(color: Color(0xFF3C4353), fontSize: 18.sp),
            ),
            online==3?Container():
            online==0?
            Container(
              decoration: BoxDecoration(
                  color: Color(0xFF08d408),
                  borderRadius: BorderRadius.circular(10.r)),
              padding: EdgeInsets.fromLTRB(10.w, 3.h, 10.w, 3.h),
              child: Row(
                children: [
                  Image.asset(
                    Constant.IMG_BASE + 'on_line.png',
                    width: 8.w,
                    height: 8.w,
                  ),
                  SizedBox(
                    width: 3.w,
                  ),
                  Text(
                    '在线',
                    style:
                    TextStyle(color: Colors.white, fontSize: 8.sp),
                  )
                ],
              ),
            ):Container(
              decoration: BoxDecoration(
                  color: Color(0xFFA5A5A5),
                  borderRadius: BorderRadius.circular(10.r)),
              padding: EdgeInsets.fromLTRB(10.w, 3.h, 10.w, 3.h),
              child: Row(
                children: [
                  Image.asset(
                    Constant.IMG_BASE + 'off_line.png',
                    width: 8.w,
                    height: 8.w,
                  ),
                  SizedBox(
                    width: 3.w,
                  ),
                  Text(
                    '休息',
                    style:
                    TextStyle(color: Colors.white, fontSize: 8.sp),
                  )
                ],
              ),
            )

          ],
        ),
      ),
      leading: hasLeading == false
          ? Text('')
          : IconButton(
        icon: Container(
          padding: EdgeInsets.all(3.0),
          child: Image.asset(
            Constant.IMG_BASE + 'ic_back.png',
            width: 15.w,
            height: 15.h,
          ),
        ),
        onPressed: () {
          if (popWithParam != null && popWithParam == true) {
            Navigator.of(context).pop('11');
          } else {
            Navigator.of(context).pop();
          }
        },
      ),
      actions: <Widget>[
        online==3?
        IconButton(
          onPressed: () {
            callBack();
          },
          icon: Icon(Icons.more_horiz,size: 28,color: Colors.grey,),
        ):Container(),
        IconButton(
          onPressed: () {
            tabbarEventBus.fire(TabChangedEvent(-1));
            Get.offAll(()=>IndexPage());
          },
          icon: Icon(Icons.home,size: 28,color: Colors.grey,),
        ),
      ],
      elevation: 0,
      backgroundColor: Colors.white,
      centerTitle: true);
}
